package com.mzj.saas.mservice.lock.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.exception.BizException;
import com.haixiaoke.saas.repository.pojo.Order;
import com.haixiaoke.saas.repository.service.IOrderPasswordRecordService;
import com.haixiaoke.saas.repository.service.IOrderService;
import com.mzj.saas.annotation.CheckAuth;
import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.CustomException;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.commons.vo.redis.TokenRedisVo;
import com.mzj.saas.mservice.lock.entity.LockFrozenSet;
import com.mzj.saas.mservice.lock.entity.SmartLock;
import com.mzj.saas.mservice.lock.entity.SmartLockAuth;
import com.mzj.saas.mservice.lock.entity.SmartLockFace;
import com.mzj.saas.mservice.lock.service.LockAppService;
import com.mzj.saas.mservice.lock.service.SmartLockAuthService;
import com.mzj.saas.mservice.lock.vo.*;
import com.mzj.saas.mservice.smartlock.service.ruanku.SmartLockService;
import com.mzj.saas.redis.RedisService;
import com.mzj.saas.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 智能锁app接口
 */
@Controller
@RequestMapping("/lockApp")
@Api(tags = "智能锁app接口")
public class LockAppController {
    @Autowired
    private LockAppService lockAppService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private SmartLockService smartLockService;
    @Autowired
    private SmartLockAuthService smartLockAuthService;
    @Autowired
    private LoginUserUtil loginUserUtil;
    @Autowired
    private IOrderPasswordRecordService iOrderPasswordRecordService;
    @Autowired
    private IOrderService iOrderService;

    /**
     * 智能锁列表
     *
     * @param accessToken   权限鉴定
     * @param houseId       房屋id
     * @param roomNumber    房号
     * @param mechineStatus 设备状态:0未激活 1正常 2冻结
     * @param pageNumber    当前页
     * @param pageSize      页数
     * @return
     */
    @GetMapping("/lockList/v2")
    @ResponseBody
    public ResultBean<ApiData<LockListVO>> lockListV2(@RequestHeader String accessToken,
                                                      @RequestParam(value = "search", required = false) String search,
                                                      @RequestParam(value = "name", required = false) String name,
                                                      @RequestParam(value = "mac", required = false) String mac,
                                                      @RequestParam(value = "houseId", required = false) String houseId,
                                                      @RequestParam(value = "communityId", required = false) String communityId,
                                                      @RequestParam(value = "buildId", required = false) Long buildId,
                                                      @RequestParam(value = "unitId", required = false) Long unitId,
                                                      @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                                      @RequestParam(value = "orgName", required = false) String orgName,
                                                      @RequestParam(value = "matchUserName", required = false) String matchUserName,
                                                      @RequestParam(value = "mechineStatus", required = false) Integer mechineStatus,
                                                      @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockAppService.lockList1(accessToken, search, name, mac, houseId, communityId, buildId, unitId,
                roomNumber, orgName, matchUserName, mechineStatus, pageNumber, pageSize);
    }


    /**
     * 授权用户列表
     *
     * @param accessToken 权限鉴定
     * @param houseId     公租房id
     * @return
     */
    @GetMapping("/lockAuth")
    @ResponseBody
    public ResultBean<LockAuthData<LockAuthVO>> lockAuth(@RequestHeader String accessToken,
                                                         @RequestParam(value = "houseId") String houseId) {
        return lockAppService.lockAuth(accessToken, houseId);
    }

    /**
     * 智能锁开门记录
     *
     * @param accessToken 权限鉴定
     * @param lockId      智能锁id
     * @param openType    开门类型：1外开门 2内开门
     * @param search      搜索条件
     * @param date        日期
     * @param pageNumber  当前页数
     * @param pageSize    页数
     * @return
     */
    @GetMapping("/lockOpenLog")
    @ResponseBody
    public ResultBean<ApiData<LockOpenLogVO>> lockOpenLog(@RequestHeader String accessToken,
                                                          @RequestParam(value = "lockId", required = false) Long lockId,
                                                          @RequestParam(value = "openType") Integer openType,
                                                          @RequestParam(value = "search", required = false) String search,
                                                          @RequestParam(value = "date", required = false) String date,
                                                          @RequestParam(value = "matchUserName", required = false) String matchUserName,
                                                          @RequestParam(value = "communityId", required = false) String communityId,
                                                          @RequestParam(value = "buildId", required = false) Long buildId,
                                                          @RequestParam(value = "unitId", required = false) Long unitId,
                                                          @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                                          @RequestParam(value = "beginDate", required = false) String beginDate,
                                                          @RequestParam(value = "endDate", required = false) String endDate,
                                                          @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockAppService.lockOpenLog(accessToken, lockId, openType, search, date, matchUserName, communityId,
                buildId, unitId, roomNumber, beginDate, endDate, pageNumber, pageSize);
    }

    /**
     * 解冻/冻结记录
     *
     * @param accessToken 权限鉴定
     * @param lockId      智能锁id
     * @param type        操作类型:0解冻 1冻结
     * @param beginDate   开始时间
     * @param endDate     结束时间
     * @param pageNumber  当前页
     * @param pageSize    页数
     * @return
     */
    @GetMapping("/frozenOrUnfrozenLog")
    @ResponseBody
    public ResultBean<ApiData<LockFrozenVO>> frozenOrUnfrozenLog(@RequestHeader String accessToken,
                                                                 @RequestParam(value = "lockId", required = false) Long lockId,
                                                                 @RequestParam(value = "matchUserName", required = false) String matchUserName,
                                                                 @RequestParam(value = "communityId", required = false) String communityId,
                                                                 @RequestParam(value = "buildId", required = false) Long buildId,
                                                                 @RequestParam(value = "unitId", required = false) Long unitId,
                                                                 @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                                                 @RequestParam(value = "type", required = false) Integer type,
                                                                 @RequestParam(value = "beginDate", required = false) String beginDate,
                                                                 @RequestParam(value = "endDate", required = false) String endDate,
                                                                 @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
        return lockAppService.frozenOrUnfrozenLog(accessToken, lockId, matchUserName, communityId, buildId, unitId,
                roomNumber, type, beginDate, endDate, pageNumber, pageSize);
    }

    /**
     * 查看授权密码
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @return
     */
    @GetMapping("/findAuthPwd")
    @ResponseBody
    public ResultBean<AuthPwdVO> findAuthPwd(@RequestHeader String accessToken,
                                             @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockAppService.findAuthPwd(accessToken, lockAuthId);
    }

    /**
     * 读取临时密码月次数和使用次数
     *
     * @param accessToken 权限鉴定
     * @param lockId      锁id
     * @return
     */
    @GetMapping("/getTempPwd")
    @ResponseBody
    public ResultBean<Object> getTempPwd(@RequestHeader String accessToken, @RequestParam(value = "lockId", required = false) Long lockId) {
        return lockAppService.getTempPwd(accessToken, lockId);
    }

    /**
     * 读取临时密码月次数和使用次数
     *
     * @param accessToken 权限鉴定
     * @param orderId     orderId 订单id
     * @param houseId     houseId 房屋id
     * @return
     */
    @GetMapping("/getTempPwdNum")
    @ResponseBody
    public ResultBean<Object> getTempPwdNum(@RequestHeader String accessToken, @RequestParam(value = "orderId", required = true) String orderId) {
        TokenRedisVo tokenVo = redisService.findTokenVo(accessToken);
        if (tokenVo == null) return ResultBean.failedResultOfToken();
//        Long lockId = 0L;
        /*List<SmartLock> byHouseId = smartLockService.findByHouseId(houseId);
        if (CollectionUtil.isNotEmpty(byHouseId)) {
            lockId = byHouseId.get(0).getId();
        }*/
//        return lockAppService.getTempPwd(accessToken, lockId);
        Order order = iOrderService.selectOrderById(orderId);
        if (!Order.ORDER_STATE_INSPECTION.equals(order.getOrderState())) {
            return ResultBean.failedResultWithMsg("订单状态异常");
        }
        int pwdNum = iOrderPasswordRecordService.selectCountByOrderId(orderId);
        Map map = new HashMap<String,Integer>();
        map.put("authorNumber",5);
        map.put("useNumber",pwdNum);
        return ResultBean.successfulResult(map);
    }

    /**
     * 申请五代锁离线密码（替换小程序申请临时密码）
     * @param accessToken
     * @param lockId
     * @param lockAuthId
     * @return
     */
    @GetMapping("/authOfflinePwd")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authOfflinePwd(@RequestHeader String accessToken,
                                               @RequestParam(value = "lockId", required = false) Long lockId,
                                               @RequestParam(value = "lockAuthId", required = false) Long lockAuthId) {
        return lockAppService.authOfflinePwd(accessToken,lockId,lockAuthId);
    }

    /**
     * 授权临时密码
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param lockId      智能锁id
     * @return
     */
    @GetMapping("/authTemporaryPwd")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authTemporaryPwd(@RequestHeader String accessToken, @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId) {
        try {
            return lockAppService.authTemporaryPwd(accessToken, lockAuthId, lockId);
        } catch (CustomException e) {
            return ResultBean.failedResultWithMsg(e.getMessage());
        }
    }


    /**
     * 嗨小克小程序授权人脸
     *
     * @param accessToken 权限鉴定
     * @param houseId     房屋id
     * @return
     */
    @GetMapping("/authorizationFace/{houseId}")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authorizationFace(@RequestHeader String accessToken, @PathVariable(value = "houseId") String houseId) {
        return lockAppService.authorizationFace(accessToken, houseId);
    }

    /**
     * 公寓授权人脸
     *
     * @return
     */
    @GetMapping("/face/{orderId}")
    @CheckAuth
    @ResponseBody
    @RepeatSubmit
    public AjaxResult authApartmentFace(@PathVariable("orderId") String orderId) {
        String token = loginUserUtil.getToken();
        return AjaxResult.success(lockAppService.authApartmentFace(token, orderId));
    }

    /**
     * 授权时效密码
     *
     * @param accessToken 权限鉴定
     * @param houseId     房屋id
     * @param minutes     授权时间
     * @return
     */
    @GetMapping("/authTimePwd")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authTimePwd(@RequestHeader String accessToken,
                                          @RequestParam(value = "houseId") String houseId,
                                          @RequestParam("orderId") String orderId/*,
                                          @RequestParam(value = "minutes") Integer minutes*/) {
        try {
            int count = iOrderPasswordRecordService.selectCountByOrderId(orderId);
            if (count >=5) {
                return ResultBean.failedResultWithMsg("临时密码申请已超过5次");
            }
            Order order = iOrderService.selectOrderById(orderId);
            if (!(order.getCheckInTime().before(DateUtil.date()) && order.getCheckOutTime().after(DateUtil.date()))) {
                return ResultBean.failedResultWithMsg("订单租赁时间异常");
            }
            return lockAppService.authTimePassword(accessToken, houseId, 30, 0, orderId);
        } catch (BizException e) {
            return ResultBean.failedResultWithMsg(e.getMessage());
        }
    }

    /**
     * 授权四代智能锁临时密码
     *
     * @param accessToken 权限鉴定
     * @return
     */
    @PostMapping("/authorizationTemporaryPwd/{houseId}")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authorizationTemporaryPwd(@RequestHeader String accessToken, @PathVariable("houseId") String houseId) {
        TokenRedisVo token = redisService.findTokenVo(accessToken);
        if (token == null) return ResultBean.failedResultOfToken();
        Long lockAuthId = 0L;
        Long lockId = 0L;
        String userId = token.getId();
        List<SmartLock> byHouseId = smartLockService.findByHouseId(houseId);
        if (CollectionUtil.isNotEmpty(byHouseId)) {
            lockId = byHouseId.get(0).getId();
        }
        SmartLockAuth smartLockAuth = smartLockAuthService.findByHouseIdAndAuthorUserId(houseId, userId);
        if (ObjectUtil.isNotNull(smartLockAuth)) {
            lockAuthId = smartLockAuth.getId();
        }
        try {
            return lockAppService.authTemporaryPwd(accessToken, lockAuthId, lockId);
        } catch (CustomException e) {
            return ResultBean.failedResultWithMsg(e.getMessage());
        }
    }


    /**
     * 授权密码
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param lockId      智能锁id
     * @param type        密码类型：1自定义密码 2 授权密码
     * @param password    自定义密码
     * @param authType    设置方式：1永久 2时间期限 3次数
     * @param value       输入值
     * @return
     */
    @GetMapping("/authPwd")
    @ResponseBody
    public ResultBean<Object> authPwd(@RequestHeader String accessToken,
                                      @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId,
                                      @RequestParam(value = "type") Integer type,
                                      @RequestParam(value = "password", required = false) String password,
                                      @RequestParam(value = "authType") Integer authType,
                                      @RequestParam(value = "value", required = false) Integer value) {
        return lockAppService.authPwd(accessToken, lockAuthId, lockId, type, password, authType, value);
    }

    /**
     * 统一授权密码
     *
     * @param accessToken
     * @param unifyAuthPwdVo 统一授权密码实体类
     * @return
     */
    @PostMapping("/unifyAuthPwd")
    @ResponseBody
    @ApiOperation("智能锁统一授权密码")
    public ResultBean<Object> unifyAuthPwd(@RequestHeader String accessToken,
                                           @RequestBody UnifyAuthPwdVo unifyAuthPwdVo) {
        return lockAppService.unifyAuthPwd(accessToken, unifyAuthPwdVo);
    }

    /**
     * 删除授权密码
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param lockId      智能锁id
     * @return
     */
    @GetMapping("/deletePwdAuth")
    @ResponseBody
    public ResultBean<Object> deletePwdAuth(@RequestHeader String accessToken,
                                            @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId) {
        return lockAppService.deletePwdAuth(lockAuthId, lockId);
    }

    /**
     * 查看授权卡
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param type        卡类型：1身份证 2CPU卡
     * @return
     */
    @GetMapping("/findAuthCard")
    @ResponseBody
    public ResultBean<AuthCardVO> findAuthCard(@RequestHeader String accessToken,
                                               @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "type") Integer type) {
        return lockAppService.findAuthCard(accessToken, lockAuthId, type);
    }

    /**
     * 授权卡
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param lockId      智能锁id
     * @param type        卡类型：1身份证 2CPU卡
     * @param cardNumber  cpu卡号/身份证号码
     * @param cardId      卡号id
     * @param authType    设置方式：1永久 2时间期限 3次数
     * @param value       输入值
     * @return
     */
    @GetMapping("/authCard")
    @ResponseBody
    public ResultBean<Object> authCard(@RequestHeader String accessToken,
                                       @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId,
                                       @RequestParam(value = "type") Integer type, @RequestParam(value = "cardNumber") String cardNumber,
                                       @RequestParam(value = "cardId") String cardId, @RequestParam(value = "authType") Integer authType,
                                       @RequestParam(value = "value", required = false) Integer value) {
        return lockAppService.authCard(accessToken, lockAuthId, lockId, type, cardNumber, cardId, authType, value);
    }

    /**
     * 授权卡(后管调用)
     */
    @GetMapping("/authCards")
    @ResponseBody
    public ResultBean<Object> authCards(
            @RequestParam(value = "lockAuthIds") String lockAuthIds, @RequestParam(value = "lockIds") String lockIds,
            @RequestParam(value = "types") String types, @RequestParam(value = "cardNumber") String cardNumber,
            @RequestParam(value = "cardId") String cardId, @RequestParam(value = "authTypes") String authTypes,
            @RequestParam(value = "values", required = false) String values) {
        return lockAppService.authCards(lockAuthIds, lockIds, types, cardNumber, cardId, authTypes, values);
    }

    /**
     * 删除授权卡
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  授权用户id
     * @param lockId      智能锁id
     * @param type        卡类型：1身份证 2CPU卡
     * @return
     */
    @GetMapping("/deleteCardAuth")
    @ResponseBody
    public ResultBean<Object> deleteCardAuth(@RequestHeader String accessToken,
                                             @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId,
                                             @RequestParam(value = "type") Integer type) {
        return lockAppService.deleteCardAuth(lockAuthId, lockId, type);
    }

    /**
     * 授权指纹
     *
     * @param accessToken
     * @param lockAuthId  授权ID
     * @param lockId      锁ID
     * @param type        密码类型：1自定义 2 授权
     * @param fingerprint 指纹数据
     * @param authType    设置方式：1永久 2时间期限 3次数
     * @param value
     * @return
     */
    @GetMapping("/authFingerprint")
    @ResponseBody
    public ResultBean<Object> authFingerprint(@RequestHeader String accessToken,
                                              @RequestParam(value = "lockAuthId") Long lockAuthId,
                                              @RequestParam(value = "lockId") Long lockId,
                                              @RequestParam(value = "type") Integer type,
                                              @RequestParam(value = "fingerprint", required = false) String fingerprint,
                                              @RequestParam(value = "authType") Integer authType,
                                              @RequestParam(value = "value", required = false) Integer value) {
        return lockAppService.authFingerprint(accessToken, lockAuthId, lockId, type, fingerprint, authType, value, true);
    }

    /**
     * 删除指纹
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  智能锁授权id
     * @param lockId      智能锁id
     * @return
     */
    @GetMapping("/deleteFingerprintAuth")
    @ResponseBody
    public ResultBean<Object> deleteFingerprintAuth(@RequestHeader String accessToken,
                                                    @RequestParam(value = "lockAuthId") Long lockAuthId, @RequestParam(value = "lockId") Long lockId) {
        return lockAppService.deleteFingerprintAuth(lockAuthId, lockId);
    }

    /**
     * 查看蓝牙授权
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  锁授权id
     * @return
     */
    @GetMapping("/findBle")
    @ResponseBody
    public ResultBean<Object> findBle(@RequestHeader String accessToken,
                                      @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockAppService.findBle(accessToken, lockAuthId);
    }

    /**
     * 查看四代蓝牙授权
     *
     * @param accessToken 权限鉴定
     * @return
     */
    @GetMapping("/findBluetoothUnlocking")
    @ResponseBody
    public ResultBean<Object> findBluetoothUnlocking(@RequestHeader String accessToken,
                                                     @RequestParam(value = "houseId") String houseId) {
        TokenRedisVo token = redisService.findTokenVo(accessToken);
        if (token == null) return ResultBean.failedResultOfToken();
        Long lockAuthId = 0L;
        String userId = token.getId();
        List<SmartLock> byHouseId = smartLockService.findByHouseId(houseId);
        SmartLockAuth smartLockAuth = smartLockAuthService.findByHouseIdAndAuthorUserId(houseId, userId);
        if (ObjectUtil.isNotNull(smartLockAuth)) {
            lockAuthId = smartLockAuth.getId();
        }
        return lockAppService.findBle(accessToken, lockAuthId);
    }

    /**
     * 授权蓝牙
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  锁授权id
     * @param lockId      锁id
     * @param authType    1永久 2时间期限
     * @param value       日期天数
     * @return
     */
    @GetMapping("/authBle")
    @ResponseBody
    public ResultBean<Object> authBle(@RequestHeader String accessToken,
                                      @RequestParam(value = "lockAuthId") Long lockAuthId,
                                      @RequestParam(value = "lockId") Long lockId,
                                      @RequestParam(value = "authType") Integer authType,
                                      @RequestParam(value = "value", required = false) Integer value) {
        return lockAppService.authBle(accessToken, lockAuthId, lockId, authType, value);
    }

    /**
     * 删除蓝牙
     *
     * @param accessToken
     * @param lockAuthId
     * @param lockId
     * @return
     */
    @GetMapping("/deleteBle")
    @ResponseBody
    public ResultBean<Object> deleteBle(@RequestHeader String accessToken,
                                        @RequestParam(value = "lockAuthId") Long lockAuthId,
                                        @RequestParam(value = "lockId") Long lockId) {
        return lockAppService.deleteBle(lockAuthId, lockId);
    }

    /**
     * 查看指纹授权
     *
     * @param accessToken
     * @param lockAuthId
     * @return
     */
    @GetMapping("/fingerprint/status")
    @ResponseBody
    public ResultBean<AuthFingerprintVO> findAuthFingerprintStatus(@RequestHeader String accessToken,
                                                                   @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockAppService.findAuthFingerprintStatus(accessToken, lockAuthId);
    }

    /**
     * 冻结/解冻智能锁
     *
     * @param accessToken
     * @param lockId
     * @param type        类型：0解冻，1冻结
     * @param reason
     * @return
     */
    @GetMapping("/frozenOrUnfrozenAuth")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> frozenOrUnfrozenAuth(@RequestHeader String accessToken,
                                                   @RequestParam(value = "lockId") Long lockId, @RequestParam(value = "type") Integer type,
                                                   @RequestParam(value = "reason", required = false) String reason) {
        return lockAppService.frozenOrUnfrozenAuth(accessToken, lockId, type, reason);
    }

    /**
     * 单用户冻结/解冻智能锁
     *
     * @param accessToken
     * @param lockId      锁id
     * @param lockAuthId  授权id
     * @param type        类型：0:解冻 1:冻结
     * @param reason      冻结备注
     * @return
     * @author shun
     * @date 2021年7月7日
     */
    @GetMapping("/person/frozenOrUnfrozenAuth")
    @ResponseBody
    public ResultBean<Object> personFrozenOrUnfrozenAuth(@RequestHeader String accessToken,
                                                         @RequestParam(value = "lockId") Long lockId,
                                                         @RequestParam(value = "lockAuthId") Long lockAuthId,
                                                         @RequestParam(value = "type") Integer type,
                                                         @RequestParam(value = "reason", required = false) String reason) {
        return lockAppService.personFrozenOrUnfrozenAuth(accessToken, lockId, lockAuthId, type, reason);
    }


    /**
     * 总后管调用 cpu卡库 冻结/解冻
     *
     * @param lockId     锁id
     * @param lockAuthId 授权id
     * @param type       类型：0:解冻 1:冻结
     * @param reason     冻结备注
     * @return
     * @author xin
     * @date 2022年6月27日
     */
    @GetMapping("/person/frozenOrUnfrozenChamada")
    @ResponseBody
    public String frozenOrUnfrozenChamada(@RequestParam(value = "lockId") Long lockId,
                                          @RequestParam(value = "lockAuthId") Long lockAuthId,
                                          @RequestParam(value = "type") Integer type,
                                          @RequestParam(value = "reason", required = false) String reason) {
        return lockAppService.frozenOrUnfrozenChamada(lockId, lockAuthId, type, reason);
    }


    /**
     * 后管调用 cpu卡库  单用户删除授权
     *
     * @param lockAuthId 授权id
     * @return
     * @author shun
     * @date 2021年7月7日
     */
    @GetMapping("/person/delCardAuth")
    @ResponseBody
    public String delCardAuth(@RequestParam(value = "lockAuthId", required = false) String lockAuthId) {
        return lockAppService.delCardAuth(lockAuthId);
    }

    /**
     * 授权全部删除(解绑)
     *
     * @param accessToken 权限鉴定
     * @param lockId      锁id
     * @return
     * @author shun
     * @date 2021年7月7日
     */
    @GetMapping("/delAllAuth")
    @ResponseBody
    public ResultBean<Object> delAllAuth(@RequestHeader String accessToken,
                                         @RequestParam(value = "lockId") Long lockId) {
        return lockAppService.delAllAuth(accessToken, lockId);
    }

    /**
     * 查询智能锁设置
     *
     * @param accessToken 权限鉴定
     * @param lockId      锁id
     * @return
     */
    @GetMapping("/findLockOptions")
    @ResponseBody
    public ResultBean<LockFrozenSet> findLockOptions(@RequestHeader String accessToken,
                                                     @RequestParam(value = "lockId") Long lockId) {
        return lockAppService.findLockOptions(accessToken, lockId);
    }

    /**
     * 智能锁设置
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/lockOptionsSetup")
    @ResponseBody
    public ResultBean<Object> lockOptionsSetup(@RequestHeader String accessToken,
                                               @RequestBody LockFrozenSetVO vo) {
        return lockAppService.lockOptionsSetup(accessToken, vo);
    }


    /**
     * 天网互联获取蓝牙密钥
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  锁授权id
     * @return
     */
    @GetMapping("/BluetoothKey")
    @ResponseBody
    public ResultBean<Object> BluetoothKey(@RequestHeader String accessToken,
                                           @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockAppService.BluetoothKey(accessToken, lockAuthId);
    }


    /**
     * 天网互联蓝牙解密
     *
     * @param accessToken 权限鉴定
     * @param decryptInfo 密钥
     * @return
     */
    @GetMapping("/deciphering")
    @ResponseBody
    public ResultBean<Object> deciphering(@RequestHeader String accessToken,
                                          @RequestParam(value = "decryptInfo") String decryptInfo) {
        return lockAppService.deciphering(accessToken, decryptInfo);
    }


    /**
     * 搜索卡数据
     *
     * @param accessToken 权限鉴定
     * @param search      关键字搜索
     * @return
     */
    @GetMapping("/cardList")
    @ResponseBody
    public ResultBean<Object> cardList(@RequestHeader String accessToken,
                                       @RequestParam(value = "search") String search) {
        return lockAppService.cardList(accessToken, search);
    }


    /**
     * 账户管理 - 账户延期
     *
     * @param accessToken 权限鉴定
     * @return
     */
    @GetMapping("/postpone")
    @ResponseBody
    @ApiOperation("账户管理-账户延期")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "houseId", value = "房屋id", required = true),
            @ApiImplicitParam(name = "cause", value = "延期原因", required = false),
            @ApiImplicitParam(name = "deferredStartTime", value = "延期开始时间 格式:yyyy-MM-dd HH:mm:ss ", required = true),
            @ApiImplicitParam(name = "deferredEndTime", value = "延期结束时间 格式:yyyy-MM-dd HH:mm:ss ", required = true)
    })
    public ResultBean<Object> postpone(@RequestHeader String accessToken,
                                       @RequestParam String houseId,
                                       @RequestParam String cause,
                                       @DateTimeFormat()
                                       @RequestParam String deferredStartTime,
                                       @RequestParam String deferredEndTime) {
        return lockAppService.postpone
                (accessToken, houseId, cause, deferredStartTime, deferredEndTime);
    }


    /**
     * 授权人脸
     *
     * @param accessToken
     * @return
     */
    @PostMapping("/authFace")
    @ResponseBody
    @RepeatSubmit
    public ResultBean<Object> authFace(@RequestHeader String accessToken,
                                       @RequestBody SmartLockFace smartLockFace) {
        return lockAppService.authFace(accessToken, smartLockFace);
    }

    /**
     * 查看人脸授权
     *
     * @param accessToken 权限鉴定
     * @param lockAuthId  锁授权id
     * @return
     */
    @GetMapping("/findFace")
    @ResponseBody
    public ResultBean<Object> findFace(@RequestHeader String accessToken,
                                       @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockAppService.findFace(accessToken, lockAuthId);
    }

    /**
     * 删除授权人脸信息
     *
     * @param accessToken 权限鉴定
     * @return
     */
    @DeleteMapping("/deleteFace")
    @ResponseBody
    public ResultBean<Object> deleteFace(@RequestHeader String accessToken,
                                         @RequestBody SmartLockFace smartLockFace) {
        return lockAppService.deleteFace(accessToken, smartLockFace);
    }

}
